// mypage/wallet/wallet.js
var app=getApp();
var my=require("../../api/my")
var util=require("../../utils/util")

Page({
  /* 页面的初始数据*/
  data: {
    money: '0.00',
    balance:'',
    userinfo: '',
    token: '',
    renovate: false
  },
  /*生命周期函数--监听页面加载*/
  onLoad: function (options) {
    var that=this;
    that.setData({userinfo:wx.getStorageSync('userinfo'),token:wx.getStorageSync('token')})
    that.get_balance()
  },
  nav_cash:function(){
    wx.navigateTo({
      url: '../userCash/userCash?balance='+this.data.balance,
    })
  },
  nav_record:function(){
    wx.navigateTo({
      url: '../cashRecords/cashRecords',
    })
  },
  onShow:function(){
    var that=this,renovate=that.data.renovate;
    if(renovate){
      that.get_balance()
      that.setData({renovate:false})
    }
  },
  get_balance:function(){
    wx.showLoading()
    var that=this;
    my.getBalance(that.data.token).then(res=>{
      wx.hideLoading()
      if(res.data.code==200){
        var money=res.data.data>=10000?util.toThousands(util.toDecimal(res.data.data)):util.toDecimal(res.data.data)
        that.setData({money:money,balance:util.toDecimal(res.data.data)})
      }
    })
  },
})